#!/usr/local/bin/python
# -*- coding:utf8 -*-
from datetime               import datetime
from django.db              import models
from apps.account.models    import UserProfile

######################
# System table 
######################
class ProgramStatus(models.Model):
    """System table.The Program status"""
    description = models.CharField(max_length=50)

    def __str__(self):
        return self.description.encode('utf-8')

    class Admin:
        list_display = ('description')
    
    class Meta:
        db_table = 'yy_sys_program_status'

######################
# Application table
######################
class Channel(models.Model):
    parent = models.IntegerField(default=0, db_index=True)
    name = models.CharField(max_length=60, db_index=True)
    sort = models.IntegerField(default=0)
    add_time = models.DateTimeField(auto_now_add=True)
    add_user = models.ForeignKey(UserProfile)
    update_time = models.DateTimeField(auto_now=True)
    update_user = models.ForeignKey(UserProfile)
    comment = models.TextField(null=True,blank=True)
    
    def __str__(self):
        return self.name.encode('utf-8')

    class Admin:
        list_display = ('id', 'parent', 'name', 
            'add_time', 'add_user', 'update_time', 'update_user')
    
    class Meta:
        db_table = 'yy_channel'
        ordering = ('sort', '-id')

class Program(models.Model):
    channel = models.ForeignKey(Channel)
    name = models.CharField(max_length=60, db_index=True)
    sort = models.IntegerField(default=0)
    have_detail = models.BooleanField(default=False, null=True, db_index=True)
    casts = models.CharField(max_length=100, blank=True, null=True, db_index=True)
    release_date = models.DateField(blank=True, null=True)
    status = models.ForeignKey(ProgramStatus)
    dubbing = models.CharField(max_length=50, null=True)
    summary = models.TextField(null=True, blank=True)
    add_time = models.DateTimeField(auto_now_add=True)
    add_user = models.ForeignKey(UserProfile)
    update_time = models.DateTimeField(auto_now=True)
    update_user = models.ForeignKey(UserProfile)

    def __str__(self):
        return self.name.encode('utf-8')
        
    class Admin:
        list_display = ('id', 'parent', 'name', 
            'add_time', 'add_user', 'update_time', 'update_user')

    class Meta:
        db_table = 'yy_program'
        ordering = ('sort', '-id')

class Item(models.Model):
    program = models.ForeignKey(Program, db_index=True)
    name = models.CharField(max_length=60, db_index=True)
    sort = models.IntegerField(default=0)
    hot = models.IntegerField(default=0)
    video_url = models.URLField(max_length=255)
    video_from = models.CharField(max_length=50, blank=True, null=True)
    have_more = models.BooleanField(default=False, db_index=True)
    add_time = models.DateTimeField(auto_now_add=True)
    add_user = models.ForeignKey(UserProfile)
    update_time = models.DateTimeField(auto_now=True)
    update_user = models.ForeignKey(UserProfile)

    def __str__(self):
        return self.name.encode('utf-8')
        
    class Admin:
        list_display = ('id', 'program', 'name', 
            'hot', 'video_url', 'video_from', 'have_more', 'add_time', 
            'add_user', 'update_time', 'update_user')
    
    class Meta:
        db_table = 'yy_item'
        ordering = ('sort', '-id')

class ItemDetail(models.Model):
    item = models.ForeignKey(Item, db_index=True)
    name = models.CharField(max_length=100, db_index=True)
    sort = models.IntegerField(default=0)
    hot = models.IntegerField(default=0)
    video_url = models.CharField(max_length=255, null=True)
    video_from = models.CharField(max_length=50, null=True)
    add_time = models.DateTimeField(auto_now_add=True)
    add_user = models.ForeignKey(UserProfile)
    update_time = models.DateTimeField(auto_now=True)
    update_user = models.ForeignKey(UserProfile)
    
    def __str__(self):
        return self.name.encode('utf-8')
        
    class Admin:
        list_display = ('id', 'item', 'name', 
            'hot', 'video_url', 'video_from', 'add_time', 'add_user',
            'update_time', 'update_user')
    
    class Meta:
            db_table = 'yy_item_detail'
            ordering = ('sort', '-id')


#***********************************************************************
# main
#***********************************************************************
# if current module
#-----------------------------------------------------------------------

if __name__ == "__main__":                      # if is the current module
    pass                                        # (ignore)
